/**
*      author: Y_Yao
*      created: 2025-03-06 14:32:45
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
int a,b,c,d;

int gcd(int x,int y)
{
    if(y == 0)return x;
    else return gcd(y,x % y);
}

int count(int x)
{
    int l = a + x - (a % x == 0 ? x : a % x);
    int r = b - b % x;
    return (r - l) / x + 1;
}


void solve()
{
    cin >> a >> b >> c >> d;
    int ans = b - a + 1 - (count(c) + count(d) - count(c * d / gcd(c,d)));
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}